﻿using MediatR;
using Microsoft.AspNetCore.Mvc;
using SystemLYH.API.Application.Command.ProcuredCommand;
using SystemLYH.Domain;
using SystemLYH.Domain.Dto;

namespace SystemLYH.API.Controllers
{
	/// <summary>
	/// 采购申请API
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class ProcuredController : ControllerBase
	{
		protected readonly IMediator _mediator;
		/// <summary>
		/// 中介者构造函数
		/// </summary>
		/// <param name="mediator"></param>
		public ProcuredController(IMediator mediator)
		{
			_mediator = mediator;
		}
		/// <summary>
		/// 采购申请添加
		/// </summary>
		/// <param name="command"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<ApiResult<int>> CreateProcured(ProcuredCreateCommand command)
		{
			ApiResult<int> result = new ApiResult<int>();
			try
			{
				result.Data = await _mediator.Send(command);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}
		/// <summary>
		/// 采购申请列表
		/// </summary>
		/// <param name="command"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<ApiResult<PageDTO<Procuredrequest>>> ShowProcured([FromQuery] ProcuredShowCommand command)
		{
			ApiResult<PageDTO<Procuredrequest>> result = new ApiResult<PageDTO<Procuredrequest>>();
			try
			{
				result.Data = await _mediator.Send(command);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}
		/// <summary>
		/// 查看采购申请详情
		/// </summary>
		/// <param name="command"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<ApiResult<Procuredrequest>> GetProcured([FromQuery] ProcuredBackfillCommand command)
		{
			ApiResult<Procuredrequest> result = new ApiResult<Procuredrequest>();
			try
			{
				result.Data = await _mediator.Send(command);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}
		/// <summary>
		/// 采购申请删除
		/// </summary>
		/// <param name="command"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<ApiResult<int>> DeleteLocation(ProcuredDeleteCommand command)
		{
			ApiResult<int> result = new ApiResult<int>();
			try
			{
				result.Data = await _mediator.Send(command);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}
		/// <summary>
		/// 采购申请修改
		/// </summary>
		/// <param name="command"></param>
		/// <returns></returns> 
		[HttpPost]
		public async Task<ApiResult<int>> UpdateLocation(ProcuredUpdateCommand command)
		{
			ApiResult<int> result = new ApiResult<int>();
			try
			{
				result.Data = await _mediator.Send(command);
			}
			catch (Exception ex)
			{
				result.Code = -1;
				result.Message = ex.Message;
				throw;
			}
			return result;
		}



	}
}
